package cn.xfdzx.android.apps.shop.activity;

import android.content.res.ColorStateList;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.adapter.HomeVPAdapter;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;
import cn.xfdzx.android.apps.shop.fragment.market.ProductFragment;
import cn.xfdzx.android.apps.shop.fragment.market.ShopFragment;
import cn.xfdzx.android.apps.shop.util.ProgressDialog;
import cn.xfdzx.android.apps.shop.util.StatusBarUtil;

public class ClassMarketPurchaseActivity extends BaseMvpActivity {

    @BindView(R.id.tl_class_market_title)
    TabLayout mTabLayout;
    @BindView(R.id.vp_class_market)
    ViewPager vpClassMarket;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.ll_state)
    LinearLayout llState;

    private List<Fragment> mFragments;
    private String[] title = {"产品", "商铺"};
    private HomeVPAdapter homeVPAdapter;
    private RelativeLayout.LayoutParams item_bar;

    @Override
    public int getLayoutId() {
        return R.layout.activity_class_market_purchase;
    }

    @Override
    public void initView() {
        initHigh();
        tvTitle.setText(getIntent().getStringExtra("title_name"));
        mFragments = new ArrayList<>();
        mFragments.add(ProductFragment.newInstance(getIntent().getStringExtra("id")));//产品
        mFragments.add(ShopFragment.newInstance(getIntent().getStringExtra("id")));//商铺
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        mTabLayout.setTabRippleColor(ColorStateList.valueOf(this.getResources().getColor(R.color.picture_color_transparent)));
        for (String tab : title) {
            mTabLayout.addTab(mTabLayout.newTab().setText(tab));
        }
        homeVPAdapter = new HomeVPAdapter(getSupportFragmentManager(), title, mFragments);
        vpClassMarket.setAdapter(homeVPAdapter);
        mTabLayout.setupWithViewPager(vpClassMarket);
    }

    private void initHigh() {
        item_bar = (RelativeLayout.LayoutParams) llState.getLayoutParams();
        item_bar.height = StatusBarUtil.getStatusBarHeight(this);
        llState.setLayoutParams(item_bar);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @OnClick({R.id.iv_back})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    protected boolean isUseFullScreenMode() {
        return true;
    }

    @Override
    public void onError(Throwable throwable) {

    }
}
